Skip to content

fix: constant-time game-server secret, loopback internal port, moderator-only /fly and /teleport - #47

Merged
NickMesser merged 4 commits into
NickMesser:rust-rewritefrom
stsiakal:sec/login-secret-and-gm-access
Oct 27, 2026
Merged

NickMesser merged 4 commits into
NickMesser:rust-rewritefrom
stsiakal:sec/login-secret-and-gm-access

Conversation

@stsiakal

Copy link
Copy Markdown

The login server compared the game-server shared secret with != and left the internal connection open after a wrong secret, so one connection could keep guessing; the shipped internal listener also accepted connections on every interface. Separately, /fly and /teleport shipped at access level 0, so any player could toggle flight and teleport across the world.

  • Compare the game-server secret with subtle::ConstantTimeEq and poison the connection on a mismatch: every later packet is ignored (a correct secret inside the five-second window cannot register it), the delayed Error reply is still sent, then the connection closes.
  • Bind the shipped InternalNetwork to 127.0.0.1; the Docker login service sets InternalNetwork__Host="*" because the game container reaches that port over the compose network and it is never published on the host. Packets from unregistered internal peers are already refused by authorize_game_server.
  • Move fly and teleport to the moderator level (50) in the shipped AccessLevels.json.

Breaking change: the shipped login InternalNetwork.Host is now 127.0.0.1. A game server running on a different host must set InternalNetwork:Host (for example "*" or the interface address); the compose login service already overrides it with InternalNetwork__Host.

Validation of executed source 60358661e (tests and full CI; the live checks below ran on 58481b71e, whose only later delta is the poison flag and its tests):

  • New socket test wrong_secret_is_refused_and_the_connection_is_closed fails on the previous handler: it receives LGRegisterGameServer with result Error and then no EOF within 2 s (Err(Elapsed), 7.02 s run). With the fix it passes: error reply after the five-second delay, then EOF (5.22 s). A second socket test wrong_secret_poisons_the_connection_before_a_correct_registration fails on the branch before this fix (the later correct secret returned Success) and passes now: a wrong secret followed by the correct one produces only the delayed Error reply. unauthorized_internal_tokens_are_rejected_over_sockets expects Error for the poisoned socket and Success for the unregistered one, and secret_comparison_accepts_only_the_exact_secret passes. Full aaemu-login: 202 lib + 6 network tests passed, 0 failed, 7 ignored (1 lib and 6 MySQL-gated).
  • shipped_internal_network_binds_loopback fails on the previous Config.json (left "*", right "127.0.0.1") and passes with the loopback default.
  • fly_and_teleport_require_moderator_access loads the shipped AccessLevels.json; on the old table a level-0 player's /fly ran instead of returning a refusal (left [] vs Insufficient privileges). Now both commands answer |cFFFF0000Insufficient privileges.|r with no fly/teleport packet, while level 50 still runs both. shipped_configuration_binds_every_section also asserts both levels. Command suite: 164 passed, 0 failed.
  • Local server stack with the headless aaemu-testclient, one account and character at access level 0:
    • Before (previous source and AccessLevels.json): /teleport solis returned [teleport] Teleporting to |cFFFFFFFFSolis Headlands, Austera|r and SCTeleportUnitPacket; /fly returned State changed to ... and SCUnitFlyingStateChangedPacket (2 commands).
    • After: both commands returned |cFFFF0000Insufficient privileges.|r, with no SCTeleportUnitPacket and no SCUnitFlyingStateChangedPacket (2 commands).
    • Login internal socket, one bad-secret registration: reply 03 00 00 00 01 (LGRegisterGameServer, result Error) followed by EOF; the login log shows Connection 127.0.0.1, bad secret key and GameServer from 127.0.0.1 disconnected about 6 s later (1 case).
  • Full cargo xtask ci on the branch: 3,929 passed, 0 failed, 177 ignored across 97 test binaries; workspace formatting, all-target Clippy with warnings denied, the packet coverage ratchet (517 S->C opcodes, 105 typeless, 65 typed but never sent) and 7 Python tests passed.

Limits: constant-time comparison is by construction (subtle::ConstantTimeEq), not a timing measurement. The five-second delayed error reply (retail/C# timing) is kept, with closure 200 ms later; a poisoned connection ignores later packets until that close, and new connections can still attempt registrations (no rate limit). The unregistered-connection handshake window and slot cap, AutoAccount, and the Docker MySQL/Adminer exposure are unchanged; the existing authorization already blocks actions from unregistered peers, but a peer can still hold an unregistered socket until it disconnects. Access levels change the shipped defaults only, so existing Config.Local.json / AccessLevels.json overrides still win. The live checks used the headless test client, not the retail 1.2 client, and /fly's per-character state cache makes the refusal, not the state text, the evidence. No full gameplay regression suite was run.

Review: an independent reviewer (R1) read the diff, the close/poison logic against network/internal.rs, every config and script that binds or uses the internal port, and every use of /fly and /teleport in scripts, the test client and the verify suites: qualified clear. Its one code finding (a correct secret sent inside the error-reply window could still register) is fixed in 60358661e with the poison test above.

🤖 Generated with Claude Code

… on mismatch

Registration compared the shared secret with != (a timing oracle) and left the internal connection open after the error reply, so one connection could keep guessing. Compare with subtle::ConstantTimeEq and, after the existing five-second error reply, close the connection.

Proof: new socket test wrong_secret_is_refused_and_the_connection_is_closed failed on the previous handler (error reply then no EOF after 2 s, 7.02 s run) and passes with the fix (5.22 s); full aaemu-login suite 201 lib + 5 network tests passed, 0 failed, 7 ignored.
The shipped login config listened on every interface for the game-server protocol, so an exposed host ran the internal unauthenticated surface (and default SecretKey) publicly. Bind 127.0.0.1 by default; the Docker login service explicitly asks for * because the game container reaches it over the compose network and the port is not published.

Proof: new shipped_internal_network_binds_loopback test failed on the previous Config.json (left *, right 127.0.0.1) and passes with the loopback default.
AccessLevels.json shipped fly and teleport at level 0, and the command manager enforces exactly that table, so any player could toggle fly mode and teleport across the world. Move both commands to the moderator level (50), like the other moderator commands; the Web API loopback default and its bearer authentication are already upstream.

Proof: new fly_and_teleport_require_moderator_access test loads the shipped AccessLevels.json and failed on the old table (level-0 fly was not refused: left [] vs Insufficient privileges) and passes now; the shipped_configuration_binds_every_section test also asserts both levels. Command suite: 164 passed, 0 failed; cargo clippy -p aaemu-game --all-targets -- -D warnings clean.
…cret

The delayed reply task left the reader running for five seconds, so a peer could send more guesses, and a wrong secret followed by the correct one in that window registered the connection (the first task then closed it). Set a poisoned flag on the connection before scheduling the reply: handle_g2l ignores every later packet, the delayed Error reply is still sent, and the connection closes 200 ms later.

Proof: new socket test wrong_secret_poisons_the_connection_before_a_correct_registration failed on the previous handler (the correct secret returned Success) and passes now; the existing token test now expects Error for the poisoned socket and Success for the unregistered one. Full aaemu-login: 202 lib + 6 network tests passed, 0 failed, 7 ignored.
@NickMesser
NickMesser merged commit 533ec2e into NickMesser:rust-rewrite Oct 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants